package framework.spatial;

import framework.FRDJPanel;
import framework.FRDModel;
import java.awt.Dimension;
import java.io.Serializable;

/**
 *
 * @author Lukáš Marek
 */
public class FRDSpatial extends FRDJPanel implements Serializable
{
	protected FRDSpatialModel model = null;

	/**
	 * Vytvori novy panel FRDSpatial
	 */
	public FRDSpatial()
	{
		initComponents();
		spatialMap = new FRDSpatialMap(this);
		spatialMap.setLocation(1, 1);
		jPanel2.add(spatialMap);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents()
  {

    jPanel1 = new javax.swing.JPanel();
    nameTextField = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    fromTextField = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    toTextField = new javax.swing.JTextField();
    saveButton = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    jLayeredPane1 = new javax.swing.JLayeredPane();
    addButton = new javax.swing.JButton();
    zoomOutButton = new javax.swing.JButton();
    zoomInButton = new javax.swing.JButton();
    endPaintButton = new javax.swing.JButton();
    deleteButton = new javax.swing.JButton();

    jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    jPanel1.setLayout(null);
    jPanel1.add(nameTextField);
    nameTextField.setBounds(90, 20, 230, 20);

    jLabel1.setText("Jméno:");
    jLabel1.setToolTipText("");
    jPanel1.add(jLabel1);
    jLabel1.setBounds(20, 20, 50, 20);
    jPanel1.add(fromTextField);
    fromTextField.setBounds(90, 60, 100, 20);

    jLabel2.setText("Platnost od:");
    jPanel1.add(jLabel2);
    jLabel2.setBounds(20, 60, 70, 20);

    jLabel3.setText("do:");
    jPanel1.add(jLabel3);
    jLabel3.setBounds(200, 60, 20, 20);
    jPanel1.add(toTextField);
    toTextField.setBounds(220, 60, 100, 20);

    saveButton.setText("Uložit");
    saveButton.setActionCommand("saveButton");
    jPanel1.add(saveButton);
    saveButton.setBounds(10, 480, 73, 23);

    jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    jPanel2.setLayout(null);

    addButton.setText("Nový");
    addButton.setActionCommand("addButton");
    addButton.setBounds(530, 10, 73, 23);
    jLayeredPane1.add(addButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

    zoomOutButton.setBackground(new java.awt.Color(255, 255, 255));
    zoomOutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/zoom_out.png"))); // NOI18N
    zoomOutButton.setToolTipText("");
    zoomOutButton.setActionCommand("zoomOutButton");
    zoomOutButton.setBorder(null);
    zoomOutButton.setBorderPainted(false);
    zoomOutButton.setContentAreaFilled(false);
    zoomOutButton.setFocusPainted(false);
    zoomOutButton.setBounds(50, 0, 40, 40);
    jLayeredPane1.add(zoomOutButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

    zoomInButton.setBackground(new java.awt.Color(255, 255, 255));
    zoomInButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/zoom_in.png"))); // NOI18N
    zoomInButton.setToolTipText("");
    zoomInButton.setActionCommand("zoomInButton");
    zoomInButton.setBorder(null);
    zoomInButton.setBorderPainted(false);
    zoomInButton.setContentAreaFilled(false);
    zoomInButton.setFocusPainted(false);
    zoomInButton.setBounds(10, 0, 40, 40);
    jLayeredPane1.add(zoomInButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

    endPaintButton.setText("Ukončit kreslení");
    endPaintButton.setActionCommand("endPaintButton");
    endPaintButton.setBounds(333, 10, 130, 23);
    jLayeredPane1.add(endPaintButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

    deleteButton.setText("Odstranit");
    deleteButton.setActionCommand("deleteButton");
    deleteButton.setBounds(183, 10, 90, 23);
    jLayeredPane1.add(deleteButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
          .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 608, Short.MAX_VALUE)
          .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(23, 23, 23))
          .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))))
    );
  }// </editor-fold>//GEN-END:initComponents

  // Variables declaration - do not modify//GEN-BEGIN:variables
  public javax.swing.JButton addButton;
  public javax.swing.JButton deleteButton;
  public javax.swing.JButton endPaintButton;
  public javax.swing.JTextField fromTextField;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  public javax.swing.JLayeredPane jLayeredPane1;
  public javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  public javax.swing.JTextField nameTextField;
  public javax.swing.JButton saveButton;
  public javax.swing.JTextField toTextField;
  public javax.swing.JButton zoomInButton;
  public javax.swing.JButton zoomOutButton;
  // End of variables declaration//GEN-END:variables
		
	private FRDSpatialMap spatialMap;

	/**
	 * Vrati referenci na objekt FRDSpatialMap
	 * @return 
	 */
	public FRDSpatialMap getSpatialMap()
	{
		return spatialMap;
	}

	/**
	 * Nastaveni modelu
	 * @param model
	 */
	@Override
	public void setModel(FRDModel model)
	{
		this.model = (FRDSpatialModel) model;
	}

	/**
	 * vraci nastaveny model, pro praci nutno pretypovat
	 * @return
	 */
	@Override
	public FRDModel getModel()
	{
		return model;
	}

	/**
	 * nastavy velikost panelu pro mapu, a velikost mapy
	 * @param x
	 * @param y 
	 */
	public void setMapSize(int x, int y)
	{
		Dimension dm = new Dimension(x, y);
		spatialMap.setSize(dm);
		spatialMap.setMaximumSize(dm);
		spatialMap.setPreferredSize(dm);
		spatialMap.setMinimumSize(dm);
		Dimension dm2 = new Dimension(x + 2, y + 2);
		jPanel2.setSize(dm2);
		jPanel2.setPreferredSize(dm2);
		jPanel2.setMinimumSize(dm2);
		jPanel2.setMaximumSize(dm2);
	}
}
